#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lc (o<<1)
#define rc (o<<1|1)
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1e5+10;
int n,q,head[MAXN],cnt,sub[MAXN];
struct edge
{
	int v,next;
}e[MAXN*2];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
struct Seg_T
{
	int sumv[MAXN<<2],covv[MAXN<<2];
	inline void push_up(int o)
	{
		sumv[o]=sumv[lc]+sumv[rc];
		return;
	}
	inline void push_down(int o,int l,int r)
	{
		int mid=(l+r)>>1;
		if(~covv[o])
		{
			covv[lc]=covv[rc]=covv[o];
			sumv[lc]=covv[o]?(mid-l+1):0;
			sumv[rc]=covv[o]?(r-mid):0;
			covv[o]=-1;
		}
		return;
	}
	void update(int o,int l,int r,int yl,int yr,int k)
	{
		if(yl<=l&&r<=yr)
		{
			sumv[o]=k?(r-l+1):0;
			covv[o]=k;
			return;
		}
		int mid=(l+r)>>1;
		push_down(o,l,r);
		if(yl<=mid)update(lc,l,mid,yl,yr,k);
		if(yr>mid)update(rc,mid+1,r,yl,yr,k);
		push_up(o);
		return;
	}
	int query(int o,int l,int r,int yl,int yr)
	{
		if(yl<=l&&r<=yr)return sumv[o];
		int mid=(l+r)>>1,ret=0;
		push_down(o,l,r);
		if(yl<=mid)ret=query(lc,l,mid,yl,yr);
		if(yr>mid)ret+=query(rc,mid+1,r,yl,yr);
		return ret;
	}
}T1;
struct Tree_D
{
	int sum[MAXN],depth[MAXN],fa[MAXN],son[MAXN],pre[MAXN],top[MAXN],cnt;
	void dfs1(int u,int lst,int dep)
	{
		fa[u]=lst;
		depth[u]=dep;
		sum[u]=1;
		int t=0;
		for(int i=head[u];i;i=e[i].next)
		{
			int v=e[i].v;
			if(v==lst)continue;
			dfs1(v,u,dep+1);
			sum[u]+=sum[v];
			if(sum[v]>t)
			{
				t=sum[v];
				son[u]=v;
			}
		}
		return;
	}
	void dfs2(int u,int lst)
	{
		top[u]=lst;
		pre[u]=++cnt;
		sub[cnt]=u;
		if(son[u])dfs2(son[u],lst);
		for(int i=head[u];i;i=e[i].next)
		{
			int v=e[i].v;
			if(v==fa[u]||v==son[u])continue;
			dfs2(v,v);
		}
		return;
	}
	int query(int u)
	{
		int ret=0;
		while(true)
		{
			int f=top[u];
			ret+=T1.query(1,1,n,pre[f],pre[u]);
			T1.update(1,1,n,pre[f],pre[u],1);
			if(f==1)break;
			u=fa[f];
		}
		return ret;
	}
}T2;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();
	for(int i=2;i<=n;++i)
	{
		int x=read()+1;
		addedge(i,x);addedge(x,i);
	}
	T2.dfs1(1,0,1);
	T2.dfs2(1,1);
	q=read();
	while(q--)
	{
		char op[10];
		scanf("%s",op);
		if(op[0]=='i')
		{
			int x=read()+1;
			printf("%d\n",T2.depth[x]-T2.query(x));
		}
		else
		{
			int x=read()+1;
			printf("%d\n",T1.query(1,1,n,T2.pre[x],T2.pre[x]+T2.sum[x]-1));
			T1.update(1,1,n,T2.pre[x],T2.pre[x]+T2.sum[x]-1,0);
		}
	}
	return 0;
}
